/*
 * Copyright (c) 2009, DanikX Corporation. All Rights Reserved.
 */

package kz.home.gui;

import kz.home.db.DBUtils;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Movies Form
 * Created by IntelliJ IDEA.
 * User: danik
 * Date: 08.07.2009
 * Time: 2:19:34
 */
public class MoviesForm extends BaseForm {
    protected Vector movies;
    protected Command cmd_Select;


    public MoviesForm(BaseForm mainScreen, Display display, Hashtable request, Vector movies) {
        super("Список фильмов", mainScreen, display, request);
        this.movies = movies;
        initMap(DBUtils.MOVIES);
        initCmd();
    }

    protected void initCmd() {
        cmd_Select = new Command("Выбрать", Command.ITEM, 1);
        addCommand(cmd_Select);
    }

    protected void addToMap(Hashtable map, Vector dataRow) {
        map.put(dataRow.elementAt(0),// id
                "" + dataRow.elementAt(1));// название фильма.;
    }

    public void addOnScreen() {
        if (movies == null) {
            // do nothing
        } else {
            for (int i = 0; i < movies.size(); i++) {
                append("" + map.get(movies.elementAt(i)) +
                        " [" + movies.elementAt(i) + "]" +
                        "\n");
            }
        }
    }

    public void commandAction(Command command, Displayable displayable) {
        super.commandAction(command, displayable);

         if (command == cmd_Select) {
            setValue("" + movies.elementAt(getSelectedIndex()));
            ResultForm form = new ResultForm("Фильм " + map.get(movies.elementAt(getSelectedIndex())), this, display, request, 2);
            display.setCurrent(form);
        }
    }

    protected String getParam() {
        return "mov";
    }
}
